package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketReceipt;
import com.ruoyi.system.service.ITicketReceiptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收据信息Controller
 *
 * @author ruoyi
 * @date 2024-07-15
 */
@RestController
@RequestMapping("/system/receipt")
public class TicketReceiptController extends BaseController
{
    @Autowired
    private ITicketReceiptService ticketReceiptService;

    /**
     * 查询收据信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:receipt:list')")
    @GetMapping("/list")
    public TableDataInfo list(TicketReceipt ticketReceipt)
    {
        startPage();
        List<TicketReceipt> list = ticketReceiptService.selectTicketReceiptList(ticketReceipt);
        return getDataTable(list);
    }

    /**
     * 导出收据信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:receipt:export')")
    @Log(title = "收据信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicketReceipt ticketReceipt)
    {
        List<TicketReceipt> list = ticketReceiptService.selectTicketReceiptList(ticketReceipt);
        ExcelUtil<TicketReceipt> util = new ExcelUtil<TicketReceipt>(TicketReceipt.class);
        util.exportExcel(response, list, "收据信息数据");
    }

    /**
     * 获取收据信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:receipt:query')")
    @GetMapping(value = "/{receiptNo}")
    public AjaxResult getInfo(@PathVariable("receiptNo") String receiptNo)
    {
        return success(ticketReceiptService.selectTicketReceiptByReceiptNo(receiptNo));
    }

    /**
     * 新增收据信息
     */
    @PreAuthorize("@ss.hasPermi('system:receipt:add')")
    @Log(title = "收据信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicketReceipt ticketReceipt)
    {
        ticketReceipt.setCreateBy(getUsername());
        return toAjax(ticketReceiptService.insertTicketReceipt(ticketReceipt));
    }

    /**
     * 修改收据信息
     */
    @PreAuthorize("@ss.hasPermi('system:receipt:edit')")
    @Log(title = "收据信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicketReceipt ticketReceipt)
    {
        ticketReceipt.setUpdateBy(getUsername());
        return toAjax(ticketReceiptService.updateTicketReceipt(ticketReceipt));
    }

    /**
     * 删除收据信息
     */
    @PreAuthorize("@ss.hasPermi('system:receipt:remove')")
    @Log(title = "收据信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{receiptNos}")
    public AjaxResult remove(@PathVariable String[] receiptNos)
    {
        return toAjax(ticketReceiptService.deleteTicketReceiptByReceiptNos(receiptNos));
    }
}
